package com.bahiaapk.util;

import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import blueprint.software.blueframe.exceptions.BlueFrameException;
import blueprint.software.blueframe.synchronize.HTTPConnect;

public class BahiaUtil {

	public static String currentYear = "2012";
	public static String TAG = "BahiaUtil";
	public static final String senderId =  "104752521310"; 
	public static final String urlServer = "";
	public static final int minimumListSize = 8;

	public static String linkAudio = "";

	
	
	public static void setToken(String registration){
		
		Log.v(TAG, "Sending token to server"+registration);
		
		HTTPConnect connect = new HTTPConnect(BahiaUtil.urlServer+"/setPushToken");
		ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();		
    	nameValuePairs.add(new BasicNameValuePair("token",registration));
    	nameValuePairs.add(new BasicNameValuePair("os","android"));
    	
    	try {
			connect.setObject("", nameValuePairs);
			Log.v(TAG, "Token GCM on server"+registration);
		} catch (BlueFrameException e) {
			Log.v(TAG, e.getMessage());
		}
    	
	}
	
	   
    public static boolean haveNetworkConnection(Context context) {    	
        boolean haveConnectedWifi = false;
        boolean haveConnectedMobile = false;

        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo[] netInfo = cm.getAllNetworkInfo();
        for (NetworkInfo ni : netInfo) {
            if (ni.getTypeName().equalsIgnoreCase("WIFI"))
                if (ni.isConnected())
                    haveConnectedWifi = true;
            if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
                if (ni.isConnected())
                    haveConnectedMobile = true;
        }
        return haveConnectedWifi || haveConnectedMobile;
    }
}
